package com.class05.jdk8.yxy01.lambda;

import org.junit.jupiter.api.Test;

import java.util.Comparator;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/17 22:59
 */
public class LambdaTest {
    @Test
    public void test1() {
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱中国");
            }

            ;
        };
        r1.run();

        System.out.println("==============");
        Runnable r2 = () -> {
            System.out.println("中国爱我");
        };
        r2.run();
    }

    @Test
    public void test2() {
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }

            ;
        };
        int compare1 = com1.compare(12, 21);
        System.out.println("compare1 = " + compare1);
        System.out.println("======================================");
//        Lambda表达式的写法
        Comparator<Integer> com = (Integer o1, Integer o2) -> Integer.compare(o1, o2);
        int compare = com.compare(23, 32);
        System.out.println(compare);
        System.out.println("======================================");
//        方法引用
        Comparator<Integer> com3 = Integer::compare;
        int compare2 = com3.compare(23, 32);
        System.out.println("compare2 = " + compare2);
        

    }

}
